package com.kingwang.training.designpattern.flyweight.bo;

import java.util.HashMap;
import java.util.Map;

/**
 * 享元工厂
 */
public class ChessPiecesFactory {
    private Map<String, ChessPieces> CHESSPIECES = new HashMap<>();

    public ChessPiecesFactory() {
        WhitePieces whitePieces = new WhitePieces();
        BlackPieces blackPieces = new BlackPieces();

        this.CHESSPIECES.put(whitePieces.getColor(), whitePieces);
        this.CHESSPIECES.put(blackPieces.getColor(), blackPieces);
    }

    public ChessPieces getChessPieces(String color) {
        if (this.CHESSPIECES.containsKey(color)) {
            return this.CHESSPIECES.get(color);
        }

        throw new IllegalArgumentException("非法的棋子类型");
    }
}
